import { Component, OnInit } from '@angular/core';
import { GlobalEventService } from 'src/server/global-event/global-event.service';
import { fromEvent } from 'rxjs';
import {debounceTime} from "rxjs/internal/operators";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  constructor(private globalEventService: GlobalEventService) { }


  ngOnInit() {
    // 防止多次订阅
    for (let key in this.globalEventService.eventArr){
      this.globalEventService.eventArr[key].observers=[]
    };
    fromEvent(window, 'resize')
      .pipe(debounceTime(100))
      .subscribe((event:any) => {
        let winObj:any = {
            width:event.target.innerWidth,
            height:event.target.innerHeight,
        };
        this.globalEventService.eventArr.windowChange.next(winObj)
      })
  }

}
